'''
装备管理相关页面测试
'''
from Lib.base.page_object.car_manager.car_add import CarAdd
from Lib.base.page_object.equipment_manager.car_equipment.car_equipment_add import CarEquipment
from Lib.base.page_object.equipment_manager.car_equipment.car_equipment_list import CarEquipmentList
from Lib.base.page_object.car_manager.car_list import CarList
from Lib.base.page_object.equipment_manager.single_equipment.single_equipment_add import SingleEquipmentAdd
from Lib.base.page_object.equipment_manager.single_equipment.single_equipment_list import SingleEquipmentList
from Lib.base.page_object.equipment_manager.other_equipment.other_equipment_add import OtherEquipmentAdd
from Lib.base.page_object.equipment_manager.other_equipment.other_equipment_list import OtherEquipmentList
from selenium.webdriver.common.by import By
import allure
import os
from Lib.common.assert_class import AssertClass
import pytest


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestVehicleEquipment.assert_class = AssertClass(login)
    TestVehicleEquipment.singleEquipment = SingleEquipmentAdd(login)
    TestVehicleEquipment.singleEquipmentList = SingleEquipmentList(login)
    TestVehicleEquipment.otherEquipmentAdd = OtherEquipmentAdd(login)
    TestVehicleEquipment.otherEquipmentList = OtherEquipmentList(login)


@allure.feature("装备管理页面测试")
class TestVehicleEquipment:

    @allure.story('单兵装备管理')
    @allure.title('新建单兵装备')
    def test_06_add_single_equipment(self):
        '''
        创建单兵装备
        :return:
        '''
        # 新增车载装备
        self.singleEquipment.single_equipment_add()
        # 设置断言
        assert_args = (By.XPATH, '//p[contains(text(), "创建成功")]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='创建成功', context='创建单兵装备')

    @allure.story('单兵装备管理')
    @allure.title('单兵装备列表筛选')
    def test_07_single_equipment_list(self):
        '''
        查看单兵装备列表
        :return:
        '''
        self.singleEquipmentList.single_equipment_list()
        # 设置断言
        assert_args = (By.XPATH, '//table[@class="rz-table__body"]//p[text()="自动化设备名称"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='自动化设备名称', context="单兵装备列表")

    @allure.story('单兵装备管理')
    @allure.title('搜索并查询单兵装备详情')
    def test_08_single_equipment_search_detail(self):
        '''
        查看单兵装备列表
        :return:
        '''
        self.singleEquipmentList.single_equipment_search_detail()
        # 设置断言
        assert_args = (By.XPATH, '//span[text()="单兵装备详情"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='单兵装备详情', context="单兵装备详情")

    @allure.story('单兵装备管理')
    @allure.title('搜索并修改单兵装备')
    def test_09_equipment_search_update(self):
        '''
        搜索车载装备并编辑
        :return:
        '''
        self.singleEquipmentList.single_equipment_search_update()
        # 设置断言
        assert_args = (By.XPATH, '//p[text()="更新成功!"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='更新成功!', context="修改单兵装备")

    @allure.story('单兵装备管理')
    @allure.title('搜索并删除单兵装备')
    def test_10_equipment_search_delete(self):
        '''
        搜索车载装备并编辑
        :return:
        '''
        self.singleEquipmentList.single_equipment_search_delete()
        # 设置断言
        assert_args = (By.XPATH, '//p[text()="所选单兵装备已删除"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='所选单兵装备已删除', context="删除单兵装备")

    @allure.story('其他装备管理')
    @allure.title('新增其他装备')
    def test_11_add_other_equipment(self):
        '''
        创建单兵装备
        :return:
        '''
        # 新增车载装备
        self.otherEquipmentAdd.other_equipment_add()
        # 设置断言
        assert_args = (By.XPATH, '//p[contains(text(), "创建成功")]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='创建成功', context='创建其他装备')

    @allure.story('其他装备管理')
    @allure.title('其他装备列表筛选')
    def test_12_other_equipment_list(self):
        '''
        查看单兵装备列表
        :return:
        '''
        self.otherEquipmentList.other_equipment_list()
        # 设置断言
        assert_args = (By.XPATH, '//table[@class="rz-table__body"]//p[text()="自动化设备名称"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='自动化设备名称', context="单兵装备列表")

    @allure.story('其他装备管理')
    @allure.title('查询其他装备并查看详情')
    def test_13_other_equipment_search_detail(self):
        '''
        查看单兵装备列表
        :return:
        '''
        self.otherEquipmentList.other_equipment_search_detail()
        # 设置断言
        assert_args = (By.XPATH, '//span[text()="其他装备详情"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='其他装备详情', context="其他装备详情")

    @allure.story('其他装备管理')
    @allure.title('查询其他装备并修改')
    def test_14_other_equipment_search_update(self):
        '''
        搜索车载装备并编辑
        :return:
        '''
        self.otherEquipmentList.other_equipment_search_update()
        # 设置断言
        assert_args = (By.XPATH, '//p[text()="更新成功!"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='更新成功!', context="修改其他装备")

    @allure.story('其他装备管理')
    @allure.title('查询其他装备并删除')
    def test_15_other_equipment_search_delete(self):
        '''
        搜索车载装备并删除
        :return:
        '''
        self.otherEquipmentList.other_equipment_search_delete()
        # 设置断言
        assert_args = (By.XPATH, '//p[text()="所选其他装备已删除"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='所选其他装备已删除', context="删除其他装备")


if __name__ == '__main__':
    pytest.main(['-s', '-v', './vehicle_equipment_test.py::TestVehicleEquipment'])
    # pytest.main(['-v', './vehicle_equipment_test.py', '--alluredir', '../result', '--clean-alluredir'])
    # os.system(r'copy ..\config\environment.properties ..\result\environment.properties')
    # os.system('allure generate  ../result -o ../report/ --clean')
